<%@ page import="com.party.core.model.system.TargetType" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>绑定商户信息</title>
    <%@include file="../include/commonFile.jsp" %>
    <%--<link rel="stylesheet" href="${ctx}/css/common/list.css">--%>
    <link rel="stylesheet" href="${ctx}/css/ui/system/member/member_form.css">
    <style type="text/css">
        #headImg_img.cover-img {
            width: 80px !important;
            height: 80px !important;
        }

        #qrUrl_img.cover-img {
            width: 150px !important;
            height: 150px !important;
        }

        .layui-tab-brief > .layui-tab-title .layui-this {
            color: #e8473f !important;
        }

        .layui-tab-brief > .layui-tab-title .layui-this:after {
            border-bottom-color: #e8473f !important;
        }

        #mchForm .layui-form-item .layui-input-inline {
            width: 280px !important;
        }
    </style>
</head>
<body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <form id="mchForm" class="layui-form mt20" method="post" action="${ctx}/wechat/account/save.do">
                <input type="hidden" name="id" value="${wechatOpenMember.id}"/>
                <input type="hidden" name="deployType" value="${wechatOpenMember.deployType}"/>
                <input type="hidden" name="type" value="${wechatOpenMember.type}"/>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">公众号名称<span class="f-verify-red">*</span></label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="nickName" lay-verify="officialReg"
                                   placeholder="公众号名称"
                                   value="${wechatOpenMember.nickName}" ${wechatOpenMember.deployType == 0? 'readonly': ''}/>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">公众号ID<span class="f-verify-red">*</span></label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="authorizerAppid" lay-verify="officialReg"
                                   placeholder="公众号ID"
                                   value="${wechatOpenMember.authorizerAppid}" ${wechatOpenMember.deployType == 0? 'readonly': ''}/>
                        </div>
                    </div>
                </div>
                <c:if test="${wechatOpenMember.deployType !=0}">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">公众号Secret<span class="f-verify-red">*</span></label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" name="secret" lay-verify="officialReg"
                                       placeholder="公众号Secret" value="${wechatOpenMember.secret}"/>
                            </div>
                        </div>
                    </div>
                </c:if>

                <div class="layui-form-item">
                    <label class="layui-form-label">公众号头像<span class="f-verify-red">*</span></label>
                    <div class="cover-content">
                        <input type="hidden" name="headImg" id="headImg" lay-verify="required"
                               value="${wechatOpenMember.headImg}"/>
                        <c:if test="${wechatOpenMember == null || empty wechatOpenMember.headImg}">
                            <span id="headImg_img" class="cover-img"
                                  style="background-image:url(${ctx}/image/posterImg.png)"></span>
                        </c:if>
                        <c:if test="${wechatOpenMember != null && not empty wechatOpenMember.headImg}">
                            <span id="headImg_img" class="cover-img"
                                  style="background-image:url('${wechatOpenMember.headImg}')"></span>
                        </c:if>
                        <a class="layui-btn layui-btn-danger" id="sel_logo_img">+添加头像</a>
                        <div class="form-word-aux">建议尺寸：120x120</div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">公众号二维码<span class="f-verify-red">*</span></label>
                    <div class="cover-content">
                        <input type="hidden" name="qrcodeUrl" id="qrUrl" lay-verify="required"
                               value="${wechatOpenMember.qrcodeUrl}"/>
                        <c:if test="${wechatOpenMember == null || empty wechatOpenMember.qrcodeUrl}">
                            <span id="qrUrl_img" class="cover-img"
                                  style="background-image:url(${ctx}/image/posterImg.png)"></span>
                        </c:if>
                        <c:if test="${wechatOpenMember != null && not empty wechatOpenMember.qrcodeUrl}">
                            <span id="qrUrl_img" class="cover-img"
                                  style="background-image:url('${wechatOpenMember.qrcodeUrl}')"></span>
                        </c:if>
                        <a class="layui-btn layui-btn-danger" id="sel_pic_img1">+添加封面图</a>
                        <div class="form-word-aux">建议尺寸：340x340</div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <a href="javascript:void(0)" class="layui-btn layui-btn-danger" lay-submit lay-filter="mchForm">立即保存</a>
                        <a href="${ctx}/wechat/account/list.do" class="layui-btn layui-btn-primary">取消</a>
                    </div>
                </div>
            </form>
        </div>
        <!--底部-->
        <%@include file="../include/footer.jsp" %>
    </section>
</div>

<script>
    $(function () {
        layui.use(['form', 'laydate', 'element'], function () {
            var form = layui.form, laydate = layui.laydate, element = layui.element;

            //自定义验证规则
            form.verify({
                commonReg: function (value) {
                    var regex = /^[^\s]+$/;
                    if (value == "") {
                        return "信息不能为空";
                    } else if (!regex.test(value)) {
                        return "不能包含空格";
                    }
                }
            });

            form.on('radio(deploy_type)', function (data) {
                inviteRadioValue = data.value;
                if (inviteRadioValue == "1") {
                    $("#official").show();
                } else {
                    $("#official").hide();
                }
            });

            //监听提交 绑定商户信息
            form.on('submit(mchForm)', function (data) {
                txz.submitObject(data.elem, function (callBack) {
                    var action = $("#mchForm").attr("action");
                    $.post(action, $('#mchForm').serialize(), function (res) {
                        typeof callBack === 'function' && callBack();
                        if (res.success) {
                            util.layerMsgSuccess("商户信息保存成功", function () {
                                window.location.href = "${ctx}/wechat/account/list.do";
                            });
                        }
                        else {
                            util.layerMsgError(res.description)
                        }
                    })
                });
                return false;
            });
        });
        $('#sel_logo_img').click(function () {
            txz.openSelImg({
                min: 1,
                max: 1,
                info: '建议尺寸：120x120',
                type: '<%=TargetType.MERCHANT.getCode()%>',
                cb: function (imgs) {
                    $('#headImg_img').css('background-image', 'url(' + imgs[0].path + ')');
                    $('#headImg').val(imgs[0].path);
                }
            })
        })

        $('#sel_pic_img1').click(function () {
            txz.openSelImg({
                min: 1,
                max: 1,
                info: '建议尺寸：340x340',
                type: '<%=TargetType.MERCHANT.getCode()%>',
                cb: function (imgs) {
                    $('#qrUrl_img').css('background-image', 'url(' + imgs[0].path + ')');
                    $('#qrUrl').val(imgs[0].path);
                }
            })
        })
    })

</script>
</body>
<script type="text/javascript">
    txz.initHeader({
        nav: [{
            name: '微信账号',
            href: '${ctx}/wechat/account/list.do'
        }, {
            name: '${wechatOpenMember.id == null? '发布' : '编辑'}',
            curr: true
        }],
        btns: [{
            name: '返回',
            href: 'javascript:history.back();',
            icon: 'back'
        }]
    });
</script>
</html>